<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>管理门店信息</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function couldDelete(id){
			$.ajax({
				url:'${ctx}/sys/store/couldDelete',
				data:{'id':id},
				async:false,
				success:function(result){
					//查询所属自己门店的商品
					var goods1 = result.goods1;
					//查询所属门店但不是该门店的上架商品
					var goods2 = result.goods2;
					//查询该门店绑定的会员
					var userList1 = result.userList1;
					//查询该门店下绑定的业务员
					var userList2 = result.userList2;
					if(goods1.length>0){
						showTip("该门店下有自己的商品,不可删除", "", 3000, 0);
						return false;
					}
					if(goods2.length>0){
						showTip("该门店存在自营上架的商品,不可删除", "", 3000, 0);
						return false;
					}
					if(userList1.length>0){
						showTip("该门店存在绑定的会员,不可删除", "", 3000, 0);
						return false;
					}
					if(userList2.length>0){
						showTip("该门店存在所属的业务员,不可删除", "", 3000, 0);
						return false;
					}
					confirmx('确定删除该门店信息','${ctx}/sys/store/delete?id='+id);
				}
			})
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/store/">管理门店信息</a></li>
		<shiro:hasPermission name="sys:store:edit"><li><a href="${ctx}/sys/store/form?pa=0">门店管理添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="store" action="${ctx}/sys/store/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
		
		    <li><label>门店名称:</label>
			<form:input path="cnName" htmlEscape="false"  placeholder="门店名称" maxlength="50" class="input-medium" id="cnName"/>
			</li>
			<li><label>门店区域:</label><form:select id="classify" path="classify" class="input-medium">
			<form:option value="" label="所属区域"/>
			<form:options items="${area}" htmlEscape="false" itemValue="id" itemLabel="name"/>
			</form:select>
			</li>
		   <li><label>门店状态:</label><form:select id="status" path="status" class="input-medium">
			    <form:option value="" label="所有"/>
			    <form:options items="${fns:getDictList('store_status')}" htmlEscape="false" itemValue="value" itemLabel="label"/>
			    </form:select>
			</li> 
			<li class="clearfix"></li>
		    <li><label>门店类型:</label><form:select id="type" path="type" class="input-medium">
			    <form:option value="" label="所有"/>
			    <form:options items="${fns:getDictList('store_type')}" htmlEscape="false" itemValue="value" itemLabel="label"/>
			    </form:select>
			</li> 
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<div style="display:none;">
		<sys:message content="${message}"/>
	</div>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
			    <th>序号</th>
				<th>门店名称</th>
				<th>门店编号</th>
				<th>门店类型</th>
				<th>所属区域</th>
				<th>联系人</th>
				<th>联系人电话</th>
				<th>地址</th>
				<th>创建时间</th>
				<th>状态</th>
				<shiro:hasPermission name="sys:store:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="store" varStatus="status">
			<tr>
			   <td>${status.index+1}</td>
			   <td><a href="${ctx}/sys/store/form?id=${store.id}&pa=2">${store.cnName }</a></td>
			   <td>${store.code }</td>
			   <td>${fns:getDictLabel(store.type, 'store_type', '')}</td>
			   <td>${store.aname}</td>
			   <td>${store.master }</td>
			   <td>${store.masterPhone }</td>
			   <td>${store.address }</td>
			   <td><fmt:formatDate value="${store.createDate }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
			    <td>${fns:getDictLabel(store.status, 'store_status', '')}</td>
				<shiro:hasPermission name="sys:store:edit"><td>
    				<a href="${ctx}/sys/store/form?id=${store.id}&pa=1">编辑</a>
					<a href="javascript:;" onclick="couldDelete('${store.id}')">删除</a>
					<c:if test="${store.status==1 }">
					<a href="${ctx}/sys/store/upStore?id=${store.id}&status=0" onclick="return confirmx('确认要失效该门店管理吗？', this.href)" id="ast">失效</a>
					</c:if>
					<c:if test="${store.status==0 }">
					<a href="${ctx}/sys/store/upStore?id=${store.id}&status=1" onclick="return confirmx('确认要恢复该门店管理吗？', this.href)">恢复</a>
					</c:if>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>